<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../lib/vue.js"></script>
</head>
<body>
    <div id="app">
        <!-- 使用keyup监听 -->
        <!-- <input type="text" v-model="firstName" @keyup="handle">
        <input type="text" v-model="lastName" @keyup="handle">
        <input type="text" v-model="fullName"> -->

        <!-- 使用watch -->
        <input type="text" v-model="firstName">
        <input type="text" v-model="lastName">
        <input type="text" v-model="fullName"> 
    </div>

    <script>
    var vm = new Vue({
        el:'#app',
        data:{
            firstName:'',
            lastName:'',
            fullName:''
        },
        methods: {
            // handle() {
            //     this.fullName = this.firstName + this.lastName
            // }
        },
        // 使用watch可以监听data中数据的变化 触发function
        // 方法的参数可以获取改变后的值 和 改变前的值
        watch: {
            firstName:function(newVal,oldVal){
                this.fullName = this.firstName+this.lastName
            },
            lastName:function(newVal,oldVal){
                this.fullName = this.firstName+this.lastName
            }
        }
    })
    </script>
</body>
</html>